import django_filters

from datacenter.models import Entity


class EntityFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(method='get_name_filter')

    class Meta:
        model = Entity
        fields = ('name',)

    def get_name_filter(self, queryset, name, value):
        if value:
            queryset = queryset.filter(name__icontains=value)
        return queryset
